
from PIL import Image
from PIL import ImageFilter
from skimage import io,color,filters,feature
from skimage import data,morphology
import platform

class ImageDemo:
    def __init__(self):
        self.plat = platform.system()
        if self.plat == "windows":
            self.path = "D:/av/"
        else:
            self.path = "/opt/data/todocker/av/"
        self.imagename = "1.jpg"

    def show(self):
        img = Image.open(self.path + self.imagename)
        # call system app to show images
        dim = (50, 50, 500, 800)
        img_new = img.crop(dim)

        v = img.getpixel((100, 100))
        print("v: ", v)
        vv = img.convert("L").getpixel((100, 100))
        print("vv: ", vv)
        # img_new.show()

    def skimage_show(self):
        img = io.imread(self.path + self.imagename)
        # print("img: ", img)
        # io.imshow(self.path + self.imagename)
        # io.show()
        # io.imshow(data.text())
        #gray_img = color.rgb2gray(img)
        #e_img = morphology.binary_erosion(gray_img)
        e_img = morphology.binary_dilation(img)
        io.imshow(e_img)
        io.show()

    def custom_show(self):
        img = Image.open(self.path + self.imagename)
        gray_img = img.convert("L")
        e_img = gray_img.filter(ImageFilter.Kernel((3,3), [1, 0, -1, 5, 0, -5, 1, 0, 1]))
        e_img.show()

    def edge_show(self):
        img = io.imread(self.path + self.imagename)
        img = color.rgb2gray(img)
        # edge = filters.sobel(img)
        edge = feature.canny(img, 3)
        io.imshow(edge)
        io.show()
        
        
